package cn.lger.icollege.dao;

import cn.lger.icollege.entity.Classroom;
import cn.lger.icollege.entity.Student;
import cn.lger.icollege.entity.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-04-15.
 */
@Repository
public interface ClassRoomDao extends JpaRepository<Classroom, Long> {
    @Query("select new Classroom (c.classId, c.className) from Classroom c join c.teachers t where t.username =:username")
    List<Classroom> findIdAndNameByTeacherUsername(@Param("username") String username);

    Classroom findByStudentsIs(Student student);

    @Query("select c from Classroom c join c.students s where s.username = :username")
    Classroom findByStudentUsername(@Param("username") String username);

    List<Classroom> findByTeachersIs(Teacher teacher);

//    @Query("select t.classrooms from Classroom c join c.teachers t where t.usenrame = :username")
//    List<Classroom> findByTeacherUsername(@Param("username") String username);


}
